Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
The mumath npm package provides a collection of mathematical utilities for common operations such as rounding, clamping, and interpolation. It is designed to be lightweight and easy to use for basic mathematical tasks.
Rounding
The rounding feature allows you to round numbers to the nearest integer. The code sample demonstrates rounding 4.6 up to 5 and 4.4 down to 4.
const mumath = require('mumath');
console.log(mumath.round(4.6)); // 5
console.log(mumath.round(4.4)); // 4
Clamping
The clamping feature restricts a number to be within a specified range. The code sample shows clamping 10 to the maximum value of 5 and -1 to the minimum value of 0.
const mumath = require('mumath');
console.log(mumath.clamp(10, 0, 5)); // 5
console.log(mumath.clamp(-1, 0, 5)); // 0
Interpolation
The interpolation feature allows you to find a value at a specific point between two numbers. The code sample demonstrates finding the midpoint (0.5) between 0 and 10, which is 5.
const mumath = require('mumath');
console.log(mumath.lerp(0, 10, 0.5)); // 5
Math.js is an extensive math library for JavaScript and Node.js. It provides a wide range of mathematical functions and supports complex numbers, matrices, and units. Compared to mumath, math.js offers a broader set of features and is suitable for more complex mathematical operations.
Lodash is a utility library that provides functions for common programming tasks, including mathematical operations. It includes methods for rounding, clamping, and interpolation, similar to mumath. However, Lodash is a more comprehensive library that covers a wide range of utilities beyond just math.
Numeral.js is a library for formatting and manipulating numbers. While it focuses more on number formatting and parsing, it also provides some basic mathematical operations. Compared to mumath, Numeral.js is more specialized in number formatting rather than general mathematical utilities.
Set of practical math utils to shorten code.
var round = require('mumath/round');
round(123.32, .5); //123.5
//require any function as
//var <fn> = require('mumath/<fn>');
round(value, precision?)
Rounds value to optional precision
, which is 1
by default.
precision(value)
Get precision from float:
1.1 → 1, 1234 → 0, .1234 → 4
clamp(value, left, right)
Return value clamped by left/right limits (or vice-versa).
mix(x, y, ratio)
Return value interpolated between x and y.
within(value, left, right)
Whether element is between left & right, including.
mod(value, min?, max)
An enhanced mod-loop — loops value within a frame.
closest(value, arr)
Get closest value out of a set.
order(value)
Get order of magnitude for a number.
order(123) → 100; order(-0.0003) → 0.0001;
mult(a, b, ...)
div(a, b, ...)
sub(a, b, ...)
add(a, b, ...)
mod(a, b, ...)
min(a, b, ...)
max(a, b, ...)
floor(a, b, ...)
ceil(a, b, ...)
log(a)
lg(a)
Simple wrappers for arythmetical functions.
gt(a,b)
gte(a,b)
lt(a,b)
lte(a,b)
eq(a,b)
ne(a,b)
Simple conditional functions.
FAQs
Practical math utils for components
The npm package mumath receives a total of 153,831 weekly downloads. As such, mumath popularity was classified as popular.
We found that mumath demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.